using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class PersonalityValueDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public PersonalityValueDA()
		{
		}

		public PersonalityValueDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the PersonalityValue table.
		/// </summary>
		public  int Insert(PersonalityValue personalityValue)
		{
			ValidationUtility.ValidateArgument("personalityValue", personalityValue);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", personalityValue.TenantID),
				new SqlParameter("@ValueText", personalityValue.ValueText)
			};

			personalityValue.ValueID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "PersonalityValueInsert", parameters));
			return personalityValue.ValueID;
		}

		/// <summary>
		/// Updates a record in the PersonalityValue table.
		/// </summary>
		public  int Update(PersonalityValue personalityValue)
		{
			ValidationUtility.ValidateArgument("personalityValue", personalityValue);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ValueID", personalityValue.ValueID),
				new SqlParameter("@TenantID", personalityValue.TenantID),
				new SqlParameter("@ValueText", personalityValue.ValueText)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "PersonalityValueUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the PersonalityValue table by its primary key.
		/// </summary>
		public  int Delete(int valueID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ValueID", valueID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "PersonalityValueDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the PersonalityValue table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "PersonalityValueDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the PersonalityValue table.
		/// </summary>
		public  PersonalityValue Select(int valueID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ValueID", valueID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "PersonalityValueSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakePersonalityValue(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the PersonalityValue table.
		/// </summary>
		public  List<PersonalityValue> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "PersonalityValueSelectAll", parameters))
			{
				List<PersonalityValue> personalityValueList = new List<PersonalityValue>();
				while (dataReader.Read())
				{
					PersonalityValue personalityValue = MakePersonalityValue(dataReader);
					personalityValueList.Add(personalityValue);
				}

				return personalityValueList;
			}
		}

		/// <summary>
		/// Selects all records from the PersonalityValue table by a foreign key.
		/// </summary>
		public  List<PersonalityValue> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "PersonalityValueSelectAllByTenantID", parameters))
			{
				List<PersonalityValue> personalityValueList = new List<PersonalityValue>();
				while (dataReader.Read())
				{
					PersonalityValue personalityValue = MakePersonalityValue(dataReader);
					personalityValueList.Add(personalityValue);
				}

				return personalityValueList;
			}
		}

		/// <summary>
		/// Creates a new instance of the PersonalityValue class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  PersonalityValue MakePersonalityValue(SqlDataReader dataReader)
		{
			PersonalityValue personalityValue = new PersonalityValue();
			personalityValue.ValueID = SqlClientUtility.GetInt32(dataReader, "ValueID", 0);
			personalityValue.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			personalityValue.ValueText = SqlClientUtility.GetString(dataReader, "ValueText", String.Empty);

			return personalityValue;
		}

		#endregion
	}
}
